package com.flymobi.fw.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Mar 7, 2008 11:53:59 AM
 * @version $Id: BaseRuntimeException.java,v 1.1 2009/11/09 03:28:28 haoxz11 Exp
 *          $
 */
@SuppressWarnings("serial")
public class BaseRuntimeException extends RuntimeException {

	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(getClass());

	private Throwable rootCause;

	/**
	 * default constructor
	 */
	public BaseRuntimeException() {
		super();
	}

	/**
	 * @param arg0
	 *            message
	 */
	public BaseRuntimeException(final String arg0) {

		// super(arg0);
		this(arg0, null);
		rootCause = this;
	}

	/**
	 * @param arg0
	 *            throwable
	 */
	public BaseRuntimeException(final Throwable arg0) {
		this("", arg0);
	}

	/**
	 * @param arg0
	 *            message
	 * @param arg1
	 *            throwable
	 */
	public BaseRuntimeException(final String arg0, final Throwable arg1) {
		super(arg0, arg1);

		if (arg1 instanceof BaseRuntimeException) {

			rootCause = ((BaseRuntimeException) arg1).rootCause;
		} else {

			rootCause = arg1;
		}

		// log.error(arg0, arg1);
	}

	public String getErrorString() {
		StringWriter out = new StringWriter();
		printStackTrace(new PrintWriter(out));
		return out.toString();
	}
}